<template>
	<view>
		<view class="cu-bar bg-white margin-top-xs solid-bottom">
			<view class="action sub-title">
				<text class="text-xl text-bold text-blue text-shadow">申请记录</text>
				<text class="text-ABC text-blue">Application record</text>
			</view>
		</view>
		
		<view class="cu-list menu-avatar margin-bottom">
			<view class="cu-item" @click="getUserDetail(item)" v-for="(item, index) in formDataList" :key="index">
				<view class="cu-avatar radius">
					<u-avatar :src="pic" size="100"></u-avatar>
				</view>
				<view class="content">
					<view class="text-shadow text-black text-bold">{{ item.applicantName }}</view>
					<view class="text-gray text-sm flex">
						<text>联系电话：{{ item.applicantPhone }}</text>
					</view>
					<view class="text-gray text-sm flex">
						<text>微信号：{{ item.applicantWechat }}</text>
					</view>
				</view>
				<view class="flex justify-between">
					<u-button size="mini" type="primary" style="margin-right: 10rpx;" @click="agreePetAdoption(item)">同意领养</u-button>
					<u-button size="mini" type="error" @click="disagreePetAdoption(item)">拒绝领养</u-button>
				</view>
			</view>
		</view>
		
		<view class="">
			<u-popup v-model="show" mode="center" width="80%" height="50%">
				<view>我的姓名: &nbsp;&nbsp;{{ userDetail.applicantName }}</view>
				<view>我的性别: &nbsp;&nbsp;{{ userDetail.applicantGender === 0 ? '女生' : '男生' }}</view>
				<view>宠物经验: &nbsp;&nbsp;{{ userDetail.applicantLesson === 0 ? '无经验' : '有经验' }}</view>
				<view>婚姻状况: &nbsp;&nbsp;{{ userDetail.applicantMarriageName }}</view>
				<view>住房情况: &nbsp;&nbsp;{{ userDetail.applicantHoursingName }}</view>
				<view>工作状态: &nbsp;&nbsp;{{ userDetail.applicantWorkStatusName }}</view>
				<view>我的职业: &nbsp;&nbsp;{{ userDetail.applicantWorkDes }}</view>
				<view>我的年龄: &nbsp;&nbsp;{{ userDetail.applicantAgeName }}</view>
				<view>已有宠物: &nbsp;&nbsp;{{ userDetail.applicantPetsName }}</view>
				<view>月收入: &nbsp;&nbsp;{{ userDetail.applicantIncomeName }}</view>
				<view>我的地址: &nbsp;&nbsp;{{ userDetail.applicantAddress }}</view>
				<view>微信号: &nbsp;&nbsp;{{ userDetail.applicantWechat }}</view>
				<view>手机号: &nbsp;&nbsp;{{ userDetail.applicantPhone }}</view>
				<view>TA的诚意: &nbsp;&nbsp;{{ userDetail.applicantMessage }}</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import {
		getAdoptionByPetSendId,
		agreePetAdoption,
		disagreePetAdoption
	} from '@/api/me/myPetAdoption.js'
	export default {
		data() {
			return {
				pic: '../../static/avatar@2x.png',
				petSendId: '',
				formDataList: [],
				show: false,
				userDetail: {}
			}
		},
		onLoad(e) {
			console.log(e.petSendId)
			this.petSendId = e.petSendId
			this.getData(e.petSendId)
		},
		methods: {
			getUserDetail(item) {
				this.show = true
				this.userDetail = item
			},
			getData(petSendId){
				getAdoptionByPetSendId(petSendId).then(res => {
					if (res.code == 0) {
						this.formDataList = res.data
					}
				})
			},
			agreePetAdoption(item) {
				agreePetAdoption(item).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '已同意领养！',
							icon: 'success'
						});
						uni.navigateTo({
							url: '/pages/release/release-send-info'
						})
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			},
			disagreePetAdoption(item) {
				disagreePetAdoption(item).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '已不同意领养！',
							icon: 'success'
						});
						this.getData(this.petSendId)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
